# League of ChangAn/items.py
class Item:
    """装备类，用于修改英雄属性"""
    def __init__(self, name, description, attack_buff=0, health_buff=0, armor_buff=0, cooldown_reduction=0):
        self.name = name
        self.description = description
        self.attack_buff = attack_buff
        self.health_buff = health_buff
        self.armor_buff = armor_buff
        self.cooldown_reduction = cooldown_reduction
        self.equipped = False
    
    def equip(self, champion):
        """装备到英雄身上，修改属性"""
        if self.equipped:
            return False
            
        # 保存原始属性用于卸装
        self.original_max_health = champion.max_health
        
        # 应用装备效果
        champion.max_health += self.health_buff
        champion.health = min(champion.health + self.health_buff, champion.max_health)
        champion.armor += self.armor_buff
        
        self.equipped = True
        return True
    
    def unequip(self, champion):
        """从英雄身上卸装，恢复原始属性"""
        if not self.equipped:
            return False
            
        # 恢复原始属性
        champion.max_health = self.original_max_health
        champion.health = min(champion.health, champion.max_health)
        champion.armor = max(0, champion.armor - self.armor_buff)
        
        self.equipped = False
        return True
    
    def get_description(self):
        """获取装备描述"""
        desc = [self.description]
        if self.attack_buff > 0:
            desc.append(f"+{self.attack_buff} 攻击力")
        if self.health_buff > 0:
            desc.append(f"+{self.health_buff} 生命值")
        if self.armor_buff > 0:
            desc.append(f"+{self.armor_buff} 护甲")
        if self.cooldown_reduction > 0:
            desc.append(f"-{self.cooldown_reduction} 技能冷却")
        return "\n".join(desc)


# 预设装备列表
def create_default_items():
    return [
        Item("精铁剑", "一把锋利的铁剑", attack_buff=2),
        Item("皮甲", "坚固的皮革护甲", armor_buff=3),
        Item("护心镜", "保护要害的金属镜", health_buff=5, armor_buff=1),
        Item("速度之靴", "提升行动速度的战靴", cooldown_reduction=1),
        Item("玄铁盾", "沉重的玄铁盾牌", armor_buff=5),
        Item("玉如意", "蕴含生命力的玉饰", health_buff=8),
        Item("霸王枪", "威力巨大的长枪", attack_buff=4),
        Item("道德经", "蕴含智慧的古籍", cooldown_reduction=2, health_buff=3),
        Item("麒麟甲", "传说中的神甲", armor_buff=7, health_buff=5),
        Item("龙泉剑", "名匠打造的宝剑", attack_buff=3, cooldown_reduction=1)
    ]